﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Web;
using System.Windows.Forms;
using IDotNet.MapLibs.Web;
using IDotNet.MapLibs.Web.Model;
using Newtonsoft.Json;

namespace TestWinFormMap
{
    [System.Runtime.InteropServices.ComVisible(true)]
    public partial class Form1 : Form
    {
        public const string MapDomain = "http://mapdev.lizhanglong.com";
        public Form1()
        {
            InitializeComponent();
            webBrowser.ObjectForScripting = this;
            TestSelectMap();
        }
        private void 修改点坐标ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TestManageMap();
        }

        private void 地图选点ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TestSelectMap();
        }

        private void 区域范围ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TestMapDrawArea();
        }

        #region ManageMap
        void TestManageMap()
        {
            var data = new ManageMapReqModel()
            {
                ReturnUrl = "ManageMapResult",
                FromType = 1,
                MapData = new List<ManageMapItemModel>()
            {
                new ManageMapItemModel()
                {
                    Id = "1",
                    InfoWindowMsg = "罗湖区翠竹路富安娜前人行道",
                    Address = "罗湖区翠竹路富安娜前人行道",
                    City = "深圳",
                    MapLabel = "1号店",
                    MapLocation = new PointModel()
                    {
                    lat = 22.56313,                                                                                                                         lng = 114.1373
                    }
                },
                 new ManageMapItemModel()
                {
                    Id = "2",
                    InfoWindowMsg = "布吉荣超花园外国语学校旁",
                    Address = "布吉荣超花园外国语学校旁",
                    City = "深圳",
                    MapLabel = "2号店",
                    MapLocation = new PointModel()
                    {
                    lat = 22.59888,
                    lng = 114.1258
                    }
                },
                new ManageMapItemModel()
                {
                    Id = "3",
                    InfoWindowMsg = "天安门",
                  Address = "天安门",
                    MapLabel = "3号店",
                    City = "北京",
                },
                new ManageMapItemModel()
                {
                    Id = "4",
                    InfoWindowMsg = "世博园",
                  Address = "世博园",
                    MapLabel = "4号店",
                    City = "上海",
                },
            }
            };
            var d = JsonConvert.SerializeObject(data);
            var bytes = Encoding.UTF8.GetBytes(d);
            var url = MapDomain+"/Map.aspx?method=manageMap";
            webBrowser.Navigate(url, null, bytes, null);
        }

        public string ManageMapResult(string res)
        {
            MessageBox.Show(res);
            var d = new ChangeMapLocationResultInfo();
            return JsonConvert.SerializeObject(d);
        }
        #endregion

        #region MapDrawArea
        void TestMapDrawArea(List<MapData> datas = null)
        {
            var data = new MapDrawAreaRequestModel()
            {
                ReturnUrl = "MapDrawAreaResult",
                FromType = 1,
                mapBelongs = new List<MapBelong>()
                    {
                        new MapBelong()
                        {
                            mapId = "001",
                            text = "大厨房"
                        },
                        new MapBelong()
                        {
                            mapId = "002",
                            text = "坂田002",
                            label = "坂田"
                        }
                    },
                mapData = datas
            };
            var d = JsonConvert.SerializeObject(data);
            var bytes = Encoding.UTF8.GetBytes(d);
            var url = MapDomain+"/Map.aspx?method=MapDrawArea";
            webBrowser.Navigate(url, null, bytes, null);
        }

        public void MapDrawAreaResult(string res)
        {
            MessageBox.Show(res);
           var data= JsonConvert.DeserializeObject<MapDrawAreaResultModel>(res);
            TestMapDrawArea(data.mapData);
        }
        #endregion

        #region SelectMap
        void TestSelectMap()
        {
            var data = new SelectMapReqModel()
            {
                ReturnUrl = "SelectMapResult",
                FromType = 1,
                CurUserLocation = new PointModel()
                {
                    lat = 22.65222,
                    lng = 114.1673
                },
                MapData = new List<SelectMapItemModel>()
            {
                new SelectMapItemModel()
                {
                    Id = "1",
                    InfoWindowMsg = "罗湖区翠竹路富安娜前人行道",
                    lat = 22.56313,
                    lng = 114.1373
                },
                 new SelectMapItemModel()
                {
                    Id = "2",
                    InfoWindowMsg = "布吉荣超花园外国语学校旁",
                    lat = 22.59888,
                    lng = 114.1258
                },
            }
            };
            var json = JsonConvert.SerializeObject(data);
            var postData = Encoding.UTF8.GetBytes(json);
            webBrowser.Navigate(MapDomain+"/Map.aspx?method=selectMap",
                null,
               postData,
               "User-Agent:2323\r\nqq:534858");
        }

        public void SelectMapResult(string res)
        {
            MessageBox.Show(res);
        }
        #endregion


    }
}
